#modeltag({tagcode:"jxbrms_systemuserinfo",id:params[0]})
#include("/common/layout/bootstrap_form_layout.html")
#@layout()

#define title()     
#(jxrb.message(actionName,"systemUserInfo"))#(systemuserinfo.user_name ??)
#end
#define head()
<script language="javascript">
  seajs.use(["jquery", "jx_msgbox_plus", "jac", "jx_check"], function ($, msgbox) {
    $("#b_submit").on("click", function () {
      if (!jxCheck.check())
        return false;
      msgbox.confirm({url: "#(controllerKey)#(action)/" + "#(params[0])"},
      function ()
      {
        msgbox.close();
        if (msgbox.messageType != 2)
          clearForm();
      }, function ()
      {
        if (msgbox.messageType != 2)
          returnInfo();
      }
      );
    })

    function clearForm()
    {
      if ('#(action)' == 'added')
      {
        $("#userCode").val("");
        $("#userName").val("");
      }
    }


    function changeUser()
    {
      msgbox.load({url: "#(jxwebpath.item)users/viewInfo/" + $("#userId").val(), type: "GET"}, function (data)
      {
        $("#dataInfo").html(data);
      });
    }


    var divPostInfoIndex = 100;
    var postInfoNames = "";
    function collectPost() {
      if ("#(action)" == 'edited')
      {
        $("input").each(
                function () {
                  if (($(this).attr("id") != undefined) && ($(this).attr("id").search("post_name") != -1)) {
                    postInfoNames += $(this).val() + ";";
                  }
                }
        );
      }
    }

    function checkRepeatPost(info, infos)
    {
      var strArray = new Array();
      strArray = infos.split(";");
      for (var i = 0; i < strArray.length; i++)
      {
        if (info == strArray[i])
        {
          alert("岗位重复，请重新选择！");
          return false;
        }
      }
      return true;
    }
    function addPostInfo()
    {
      collectPost();
      var postInfo = $("#pName").val();
      var postId = $("#post_id").val();
      console.log("postInfo=" + postInfo);
      console.log("postId=" + postId);
      if (postInfoNames == "")
      {
        postInfoNames += "";
      }
      console.log("postInfoNames=" + postInfoNames)
      if (checkRepeatPost(postInfo, postInfoNames))
      {
        $("#addPostInfo").append('<div id="divPostInfo_' + divPostInfoIndex + '"><input type="text" name="postName" value="' + postInfo + '"  id="post_name" disabled="disabled"/><input type="hidden" name="postId" value="' + postId + '" id="post_id" />&nbsp;<input type="button" class="remove" value="删除岗位" /></div>').find("input.remove").click(function () {
          $(this).parent().remove();
        });

      }
      postInfoNames += postInfo + ";";
      divPostInfoIndex++;
    }
    function deletePostInfo(o)
    {
      document.getElementById("addPostInfo").removeChild(document.getElementById("divPostInfo_" + o));
    }

    function pageDataRefresh(strUrl)
    {
      msgbox.load({url: encodeURI(strUrl), type: "GET"}, function (data)
      {
        $("#dataInfo").html(data);
      });
    }

    $(function ()
    {
      if ('#(action)' == "edited")
      {
        pageDataRefresh(encodeURI('#(jxwebpath.item)users/viewInfo/#(systemuserinfo.user_id ??)'));
      }
    });
    var action = '#(action)';
    $("#b_return").on("click", function () {
      if (action == 'added') {
        location.href = "#(backurl)";
      } else {
        returnInfo()
      }
    });

    function returnInfo()
    {
      var parentId = $("#parentId").val();
      if (parentId == "") {
        location.href = "#(controllerKey)1-1"
      } else {
        location.href = "#(controllerKey)2-" + parentId;
      }
    }
    window.addPostInfo = addPostInfo;
    window.deletePostInfo = deletePostInfo;
    window.changeUser = changeUser;
    window.collectPost = collectPost;
  });
</script>
#end

#define form()

#include("info.html")

<div id="dataInfo">

</div>
#end

#define formAfter()
<center>
  #jx_button({value:"action.save",class:"btn btn-primary"})&nbsp;&nbsp;&nbsp;&nbsp;
  #jx_button({value:"action.return",id:"b_return",class:"btn btn-danger"})
</center>
#end